package com.fivefu.core.skyeye.event.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.skyeye.event.services.DbAiEventService;
import com.fivefu.core.skyeye.event.services.MimirEventService;
import com.fivefu.core.skyeye.event.vo.EventBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 事件表 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-08-25 14:37:19
 */
@Api(tags = "事件")
@RestController
@RequestMapping("/aiEevent")
public class DbAiEventController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(DbAiEventController.class);

    @Autowired
    private DbAiEventService aiEventService;
    @Autowired
    private MimirEventService mimirEventService;

    @ApiOperation(value = "获取事件列表(分页请传limit和page)",httpMethod = "POST",response = ResultInfo.class,notes = "获取事件列表(分页请传limit和page)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页(分页查询时必填)",paramType = "query",required = false, dataType = "int"),
            @ApiImplicitParam(name = "limit",value = "每页显示条数(分页查询时必填)",paramType = "query",required = false, dataType = "int"),
            @ApiImplicitParam(name = "cameraid",value = "探头编号",paramType = "query",required = false, dataType = "String"),
            @ApiImplicitParam(name = "sceneid",value = "场景编号",paramType = "query",required = false,dataType = "String")
    })
    @RequestMapping(path = "/getAiEventList",method = RequestMethod.POST)
    public ResultInfo getAiEventList(Integer page,Integer limit,String cameraid,String sceneid) {
        logger.info("获取事件列表接收的参数："+ JSON.toJSONString(request.getParameterMap()));
        try {
            Page<Map<String, Object>> result = aiEventService.getAiEventList(page,limit,cameraid,sceneid);
            return ResultInfo.renderSuccess(result);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return   ResultInfo.renderError("获取事件列表失败");
    }

    @ApiOperation(value = "查看事件详情",httpMethod = "POST",response = ResultInfo.class,notes = "查看事件详情")
    @ApiImplicitParam(name = "eventid",value = "事件编号",paramType = "query",required = true,dataType = "Long")
    @RequestMapping(path = "/getEventInfo",method = RequestMethod.POST)
    public ResultInfo getEventInfo(Long eventid) {
        logger.info("查看事件详情接收的参数："+ JSON.toJSONString(request.getParameterMap()));
        try {
            if (null == eventid) {
                return ResultInfo.renderError("事件编号不能为空");
            }
            Map<String,Object> resultMap = aiEventService.getEventInfo(eventid);
            return ResultInfo.renderSuccess(resultMap);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return   ResultInfo.renderError("查看事件详情失败");
    }

    @ApiOperation(value = "查看违停事件信息",httpMethod = "POST",response = ResultInfo.class,notes = "查看违停事件信息")
    @ApiImplicitParam(name = "code",value = "探头唯一标识",paramType = "query",required = true,dataType = "String")
    @RequestMapping(path = "/getIllegalEvent",method = RequestMethod.POST)
    public ResultInfo getIllegalEvent(String code) {
        logger.info("查看违停事件信息接收的参数："+ JSON.toJSONString(request.getParameterMap()));
        try {
            if (StrUtils.isNull(code)) {
                return ResultInfo.renderError("探头唯一标识不能为空");
            }
            List<EventBean> eventBeans = mimirEventService.queryMimirEventByMimirID(code);
            return ResultInfo.renderSuccess(eventBeans);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return   ResultInfo.renderError("查看违停事件信息失败");
    }

    @ApiOperation(value = "查看通用事件信息",httpMethod = "POST",response = ResultInfo.class,notes = "查看通用事件信息")
    @ApiImplicitParam(name = "code",value = "探头唯一标识",paramType = "query",required = true,dataType = "String")
    @RequestMapping(path = "/getEvent",method = RequestMethod.POST)
    public ResultInfo getEvent(String code) {
        logger.info("查看通用事件信息接收的参数："+ JSON.toJSONString(request.getParameterMap()));
        try {
            if (StrUtils.isNull(code)) {
                return ResultInfo.renderError("探头唯一标识不能为空");
            }
            List<EventBean> eventBeans = mimirEventService.queryCvMimirEventByMimirID(code);
            return ResultInfo.renderSuccess(eventBeans);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return   ResultInfo.renderError("查看通用事件信息失败");
    }


}
